﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FimetContoDeposito.BLL.Facades;
using FimetContoDeposito.DAL;
using Microsoft.Reporting.WebForms;

namespace FimetContoDeposito.OperationReports
{
    public partial class ReportTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //string m_idMovimentoCarico = "F15AE01A-76BF-4876-8935-667F540F8633";
                string m_idMovimentoCarico = Request.QueryString["id"];
                int m_tipoMovimento = int.Parse(Request.QueryString["t"]);

                Guid m_id = Guid.Parse(m_idMovimentoCarico);
                ReportDataSource datasource = null;
                ReportDataSource datasource1 = null;

                ReportViewer1.ProcessingMode = ProcessingMode.Local;
                ReportViewer1.LocalReport.EnableExternalImages = true;

                using (MovimentiFacade m_mf = MovimentiFacade.Create())
                {
                    if (m_tipoMovimento == 0)
                    {
                        ReportViewer1.LocalReport.ReportPath = Server.MapPath("../Reports/Report1.rdlc");

                        List<FCD_GetDocumentoCaricoReturnModel> m_ds = m_mf.GetDocumentoMovimentoCarico(m_id);
                        List<GetDettaglioMovimentoReturnModel> m_dsd = m_mf.GetDettaglioMovimentoCarico(m_id);

                        foreach (GetDettaglioMovimentoReturnModel m in m_dsd)
                        {
                            m.foto = string.Format("file://{0}{1}", Server.MapPath("../"), m.foto);
                        }

                        datasource = new ReportDataSource("dsDocumentoMovimentoCarico", m_ds);
                        datasource1 = new ReportDataSource("dsDettaglioMovimentoCarico", m_dsd);
                    }
                    else
                    {
                        ReportViewer1.LocalReport.ReportPath = Server.MapPath("../Reports/ReportMovScarico.rdlc");

                        List<FCD_GetDocumentoScaricoReturnModel> m_ds = m_mf.GetDocumentoMovimentoScarico(m_id);
                        List<FCD_GetDettaglioMovimentoScaricoReturnModel> m_dsd = m_mf.GetDettaglioMovimentoScarico(m_id);

                        foreach (FCD_GetDettaglioMovimentoScaricoReturnModel m in m_dsd)
                        {
                            m.foto = string.Format("file://{0}{1}", Server.MapPath("../"), m.foto);
                        }

                        datasource = new ReportDataSource("dsDocumentoMovimento", m_ds);
                        datasource1 = new ReportDataSource("dsDettaglioMovimento", m_dsd);
                    }

                    if ((datasource != null) && (datasource1 != null))
                    {
                        ReportViewer1.LocalReport.DataSources.Clear();
                        ReportViewer1.LocalReport.DataSources.Add(datasource);
                        ReportViewer1.LocalReport.DataSources.Add(datasource1);
                    }
                }

            }
        }
    }
}